﻿using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using System.Xml.Linq;

namespace EasyXaf.LowCode.WorkflowEditors.Models.Activities;

[DomainComponent]
[ImageName("WF_ForEach")]
[XafDisplayName("集合循环(ForEach)")]
[ActivityOrder(30)]
[ActivityGroup(ActivityGroupConsts.CommonGroupName)]
public class ForEachActivity : ContainerActivity
{
    public override string ImageName => "WF_ForEach";

    public override bool HasDetailView => true;

    [XafDisplayName("集合")]
    public string Collection
    {
        get => GetPropertyValue<string>();
        set => SetPropertyValue(value);
    }

    [XafDisplayName("集合项名")]
    public string ItemName
    {
        get => GetPropertyValue<string>();
        set => SetPropertyValue(value);
    }

    public ForEachActivity(IWorkflow workflow, ISequence sequence)
        : base(workflow, sequence)
    {
        Caption = "集合循环";
    }

    public override void WriteStateToXml(XElement element)
    {
        base.WriteStateToXml(element);

        SetXmlValue(element, nameof(Collection), Collection);
        SetXmlValue(element, nameof(ItemName), ItemName);
    }

    public override void ReadStateFromXml(XElement element)
    {
        base.ReadStateFromXml(element);

        Collection = GetXmlValue<string>(element, nameof(Collection));
        ItemName = GetXmlValue<string>(element, nameof(ItemName));
    }
}
